/**
 * Created by Administrator on 2015/6/19.
 */

/**
 * 绑定回车
 *
 * Added By Zmt
 */
$().ready(function ()
{
    $("#account, #password").bind("keypress", function(event){
        if("13" == event.keyCode)
            submitForm();
    });
});

var account, password;
var npwa, oldpw, npw;
// End
function submitPwd() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/user/modfPwd.do",
        async: false,
        data: {npwa: $('#npwa').val(), oldpw: $('#oldpw').val(), npw: $('#npw').val()},
        success: function (obj) {
            if (obj) obj = jQuery.parseJSON(obj);
            if (obj.ok) {
                alert("修改成功");
                closePwdBox();
            } else {
                alert(obj.msg);
            }
        }
    });
}
function submitForm() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/user/doLogin.do",
        async: false,
        data: {name:$('#account').val(),pwd: $('#password').val()},
        success: function (result) {
            var data = $.parseJSON(result);
            if (data.ok) {
                window.parent.location.href = "/user/doMain.do";
            } else {
                alert(data.msg);
            }
        }
    });
    return false;//必须要返回false，否则在某些情况下页面无法跳转
}

function clearForm() {
    account.val("");
    password.val("");
}
function modfPwd() {
    clearinput();
    $("#user_modification").dialog({
        dialogClass: "my-dialog",
        autoOpen: true,
        width: 500,
        modal: true,
        title: "修改密码",
        buttons: {
            "保存": function () {
                submitPwd();
            },
            取消: function () {
                $(this).dialog("close");
            }
        }
    });
};
function closePwdBox() {
    clearinput();
    $('#user_modification').dialog('close');
}
function clearinput() {
    $('#oldpw').val("");
    $('#npw').val("");
    $('#npwa').val("");
}